package com.zhixiang.wbl.visitor.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.zhixiang.wbl.visitor.R;

/**
 * Created by dongzhixiang on 16/5/20.
 */
public class MyPopupWindow extends PopupWindow implements View.OnClickListener
{
    private View mainview;
    private TextView takePictureTV;
    private TextView selectFromSDTV;
    private TextView cancelTV;
    private OnPopWindowItemClickListener mListner;
    public MyPopupWindow(Context context, OnPopWindowItemClickListener itemClick)
    {
        super(context);
        LayoutInflater inflater=(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
        mainview=inflater.inflate(R.layout.template_image_pick, null);

        takePictureTV =(TextView) mainview.findViewById(R.id.tvTakeHeader);
        selectFromSDTV = (TextView)mainview.findViewById(R.id.tvHeaderFromSD);
        cancelTV = (TextView)mainview.findViewById(R.id.tvCancel);
        takePictureTV.setOnClickListener(this);
        selectFromSDTV.setOnClickListener(this);
        cancelTV.setOnClickListener(this);
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setContentView(mainview);
        this.setFocusable(true);
        this.setAnimationStyle(R.style.AnimFade);
        mListner = itemClick;

    }

    @Override
    public void onClick(View v)
    {
      switch (v.getId())
      {
          case R.id.tvTakeHeader:
              mListner.onClick(0);
              break;
          case R.id.tvHeaderFromSD:
              mListner.onClick(1);
              break;
          case R.id.tvCancel:
              mListner.onClick(2);
              break;
      }
    }

    public interface OnPopWindowItemClickListener
    {
        void onClick(int position);
    }
}
